#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QContextMenuEvent>
#include <QCoreApplication>
#include <QImage>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QMainWindow>
#include <QMessageBox>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QPainter>
#include <QPixmap>
#include <QRegularExpression>
#include <QtNetwork>
#include "Positioning.h"
#include "WeatherData.h"
QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

protected:
    void contextMenuEvent(
        QContextMenuEvent *event); //重写 QWidget 的 contextMenuEvent 虚函数来实现鼠标右键点击时显示事件

    void mousePressEvent(QMouseEvent *event); //重写

    void mouseMoveEvent(QMouseEvent *event);

    void getWeatherInfo(QString cityName); //获取天气信息

    void parseJson(QByteArray &byteArray);

    void updateUI(); //更新UI

    //重写父类的eventfilter方法
    bool eventFilter(QObject *watched, QEvent *event);

    //绘制高低温曲线
    void paintTopCurve();
    void paintBottomCurve();

    //解析本机外网IP,并获取所在市
    void locationInfo();

    /*
    @brief 检测当前网卡是否是虚拟网卡(VMware/VirtualBox)或回环网卡
    @param str_card_name  网卡的描述信息
    @return 如果是虚拟网卡或回环网卡，返回true, 否则返回false
    */
    bool is_virtual_network_card_or_loopback(QString str_card_name);

    //获取本机私有IP地址
    QString getIP();

    //获取本机公有IP地址
    void GetLocalIP(QMap<QString, int> &map_ip);

private slots:
    void on_btn_search_clicked();
    //处理定位API请求
    void onLocationInfoReceived(QNetworkReply *reply);

private:
    Ui::MainWindow *ui;
    QMenu *mExitMenu;  //右键退出的菜单
    QAction *mExitACt; //退出的行为  -菜单项

    QPoint mOffset; //窗口移动时，鼠标与窗口左上角的偏移

    //Http请求
    QNetworkAccessManager *mNetAccessManger;

    //定位用的API的请求
    QNetworkAccessManager *mLocationManger;

    void onReplied(QNetworkReply *reply);

    Today mToday;
    Day mDay[6];

    //定位数据
    location mlocation;

    //星期和日期的控件数组
    QList<QLabel *> mWeekList;
    QList<QLabel *> mDateList;

    //天气和天气图标
    QList<QLabel *> mTypeList;
    QList<QLabel *> mTypeIconList;

    //天气污染指数
    QList<QLabel *> mAqiList;

    //风力和风向
    QList<QLabel *> mFxList;
    QList<QLabel *> mFlList;

    QMap<QString, QString> mTypeMap;
};
#endif // MAINWINDOW_H
